package com.xadmin.sys.rbac.service.impl;

import com.xadmin.sys.common.utils.Page;
import com.xadmin.sys.rbac.mapper.RoleMapper;
import com.xadmin.sys.rbac.pojo.Menu;
import com.xadmin.sys.rbac.pojo.Role;
import com.xadmin.sys.rbac.pojo.RoleAndMenu;
import com.xadmin.sys.rbac.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author vic Ly
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    /**
     * @param page
     * @return List<Role>
     * @Description 分页查询
     * @Param page
     */
    @Override
    public Page<Role> getAllByPage(Page<Role> page) {
        List<Role> roleList = roleMapper.getAllByPage(page);
        page.setList(roleList);
        int tatalCount = roleMapper.getCountByPage(page);
        page.setTotalCount(tatalCount);
        return page;
    }

    /**
     * @param roleName
     * @return int
     * @Description 查询总数
     * @Param page
     */
    @Override
    public Role getByName(String roleName) {
        return roleMapper.getByName(roleName);
    }

    /**
     * @param id
     * @return Menu
     * @Description 查询角色所拥有的导航菜单
     * @Param id
     */
    @Override
    public List<Menu> getMenuByRoleId(Integer id) {
        return roleMapper.getMenuByRoleId(id);
    }

    /**
     * @param id
     * @return Menu
     * @Description 查询角色所拥有的权限菜单和按钮
     * @Param id
     */
    @Override
    public List<Menu> getMenuByRoleIds(Integer id) {
        return  roleMapper.getMenuByRoleIds(id);
    }

    /**
     * @param idList
     * @return int
     * @Description 为用户批量添加菜单
     * @Param idList
     */
    @Override
    public int addMenus(List<RoleAndMenu> idList) {
        return roleMapper.addMenus(idList);
    }

    /**
     * @param id
     * @return int
     * @Description 删除角色所拥有的所有菜单
     * @Param id
     */
    @Override
    public int deleteMenus(Integer id) {
        return roleMapper.deleteMenus(id);
    }


}
